import json

import requests

# 百度翻译的URL
url = "https://fanyi.baidu.com/sug"
# 模拟的浏览器版本
headers = {
    "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"
}
# 要发送的请求体
payload = {
    "kw": "face to face"
}

r = requests.post(url=url, headers=headers, data=payload)

print(r.text)

# 可以使用json.dumps(字典)--->json字符串
# 将一个字符串格式的字典（相当于json字符串），转换为python中的字典
text_dict = json.loads(r.text)
print(type(text_dict))

k = text_dict.get("data")[0].get("k")
v = text_dict.get("data")[0].get("v")

print(k)
print(v)

